package com.robinmouren.context;

import com.robinmouren.constant.MessageConstant;
import com.robinmouren.exception.BaseException;
import com.robinmouren.exception.UnknownException;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 本地类，用与获取本地id等有关信息
 * @author Robinmouren
 */
public class LocalContext {


    /**
     * 获取本地ip
     * @return
     */
    public static String fetchLocalIp(){
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            return localHost.getHostAddress();
        } catch (UnknownHostException e) {
            throw new UnknownException(MessageConstant.UNKNOWN_LOCAL_IP);
        }
    }


}
